package practice;

import java.util.Arrays;

public class _构造乘积数组_ {
    public static void main(String[] args) {
        _构造乘积数组_ c = new _构造乘积数组_();
        _构造乘积数组_.Solution s = c.getSolution();
        int[] A = {2,3,5,4};
        int[] newA = s.multiply(A);
        for (int i = 0; i < A.length; i++) {
            System.out.print(A[i] + "  ");
        }
        System.out.println(" ");
        for (int i = 0; i < newA.length; i++) {
            System.out.println(newA[i] + "  ");
        }
    }

    Solution getSolution() {
        return new Solution();
    }

    class Solution {
        public  int[] multiply(int[] A){
            int[] B = new int[A.length];
            for (int i = 0; i < B.length; i++) {
                B[i] = ope(A,i);
            }
            return B;
        }

        public  int ope(int[] A, int i) {
            int[] temp = Arrays.copyOfRange(A,0,A.length);
            temp[i] = 1;
            int res = 1;
            for (int j = 0; j < temp.length; j++) {
                res *= temp[j];
            }
            return res;
        }
    }

}
